<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">会员信息表</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite>会员信息表</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
                      搜索：  <select id="member-search-key">
            <option value="">-请选择-</option>

                 <option value="name">姓名</option>
                 <option value="nickname">昵称</option>

                 </select>&emsp;
            <input id="member-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="member-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="member-table" lay-filter="member-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="member-table-bar">
 {{#   if(admin.hasPerm("member:member:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }} 
 {{#  if(admin.hasPerm("member:member:delete") ){   }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
 {{#     } }} 
</script>


<script type="text/html" id="toolbar">
     {{#  if(admin.hasPerm("member:member:save")){ }}
     <button id="member-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
     {{#     } }} 
 
</script>

<script type="text/html" id="strSex">
    {{#   if(d.sex==1){   }}
    <label class="layui-form-label">男</label>
    {{#     } }}
    {{#   if(d.sex==2){   }}
    <label class="layui-form-label">女</label>
    {{#     } }}
</script>
<script type="text/html" id="strIsTeacher">
    {{#   if(d.isTeacher==1){   }}
    <label class="layui-form-label">是</label>
    {{#     } }}
    {{#   if(d.isTeacher==0){   }}
    <label class="layui-form-label">否</label>
    {{#     } }}
    {{#   if(d.isTeacher==null){   }}
    <label class="layui-form-label">否</label>
    {{#     } }}
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#member-table',
            url: config.base_server + 'member/member/list',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},


                           {field: 'name',   title: '姓名'},
                           {field: 'nickname',   title: '昵称'},
                           {field: 'sex',  title: '性别',toolbar:'#strSex'},
                           {field: 'age',   title: '年龄'},
                           {field: 'isTeacher',   title: '是否大师',toolbar:'#strIsTeacher'},
                           // {field: 'teacherId',  title: '老师ID，如果是'},
                           // {field: 'summary',   title: '职称等头衔'},
                           // {field: 'introduction',  title: '简介'},
                           {field: 'phone', title: '电话'},
                           {field: 'careerYears',   title: '从业年限'},
                           // {field: 'careerFields',   title: '从业领域'},
                           {field: 'country',   title: '国家'},
                           {field: 'province',   title: '省份'},
                           {field: 'city',   title: '城市'},
                           // {field: 'headimgurl',  title: '头像'},
                           {field: 'openid',   title: 'OPENID'},
                           // {field: 'unionid',   title: 'union-id'},
                           {field: 'status',   title: '状态'},
                           {field: 'businessName',  title: '所属商家'},
                           // {field: 'referralCode',  title: '推荐码'},
                           // {field: 'privilege',   title: '特权信息'},
                           // {field: 'tags',   title: '个人标签'},
                           // {field: 'evalScore',   title: '评价得分'},
                           // {field: 'evalPeoplenum',  title: '评价人数'},
                           // {field: 'askPeoplenum',   title: '咨询人数'},
                           {field: 'createDate',   title: '创建日期'},
                           // {field: 'updateDate',   title: '更新日期'},
                        
                {fixed: 'right', align: 'center', toolbar: '#member-table-bar', title: '操作', width: 175}
            ]]
        });
        
        laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
			  $(".layui-card-body .toolbar").append(html);
			  element.render('nav');
		  });

        // 添加按钮点击事件
        $('#member-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(member-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            }  else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('member/member/delete/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('member-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '修改用户' : '添加用户';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_member', data);
            admin.popupCenter({
                area:'800px',
                title: title,
                path: 'pages/member/member_form.html',
                finish: function () {
                    table.reload('member-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#member-btn-search').click(function () {
            var key = $('#member-search-key').val();
            var value = $('#member-search-value').val();
            table.reload('member-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
